Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix EditorPlugin.remove_inspector_plugin() instance cleanup #55658

Merged
merged 1 commit into from
Dec 6, 2021

Conversation

timothyqiu
Copy link
Member

Fixes #55648

for (int i = idx; i < inspector_plugin_count - 1; i++) {
inspector_plugins[i] = inspector_plugins[i + 1];
}
if (idx == inspector_plugin_count - 1) {
inspector_plugins[idx] = Ref<EditorInspectorPlugin>();
}
inspector_plugin_count--;

It's safe only if you remove inspector plugins in a LIFO fashion.

Since all elements after idx are moved forward by one, we should always unreference the last element in use.

@timothyqiu timothyqiu added bug topic:editor topic:plugin cherrypick:3.x Considered for cherry-picking into a future 3.x release cherrypick:3.4 labels Dec 6, 2021
@timothyqiu timothyqiu added this to the 4.0 milestone Dec 6, 2021
Copy link
Member

@lawnjelly lawnjelly left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good. 👍

I was unsure about the method of not explicitly deleting but it seems okay it should be handled by refcounts. Overwriting element idx should send refcount to 0 and delete it, and set refcount to 2 for the one that overwrites, then one in turn as that is overwritten. The exception is the last element which remains at 2, and needs the explicit setting to NULL which sets the last but one ref count to 1 (from 2).

@akien-mga akien-mga merged commit 0c92edd into godotengine:master Dec 6, 2021
@akien-mga
Copy link
Member

Thanks!

@timothyqiu timothyqiu deleted the remove-inspector-plugin branch December 6, 2021 07:55
@akien-mga
Copy link
Member

Cherry-picked for 3.5.

@akien-mga akien-mga removed the cherrypick:3.x Considered for cherry-picking into a future 3.x release label Dec 6, 2021
@akien-mga
Copy link
Member

Cherry-picked for 3.4.1.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

EditorPlugin.remove_inspector_plugin() doesn't clean references, creating leaked instances at exit
3 participants